package com.qibiao.drawdemo.slice;

import com.qibiao.drawdemo.Draw;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.DirectionalLayout.LayoutConfig;
import ohos.agp.components.element.ShapeElement;

public class MainAbilitySlice extends AbilitySlice {

    private DirectionalLayout directionalLayout = new DirectionalLayout(this);

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT);
        directionalLayout.setLayoutConfig(config);

        Draw draw = new Draw(this);
        draw.setLayoutConfig(config);
        ShapeElement element = new ShapeElement();
        element.setRgbColor(new RgbColor(0, 0, 0));
        draw.setBackground(element);

        LayoutConfig btnconfig = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        Button clearBtn = new Button(this);
        clearBtn.setLayoutConfig(btnconfig);
        clearBtn.setText("擦除");
        clearBtn.setTextSize(30);
        clearBtn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                draw.Clear();
            }
        });
        directionalLayout.addComponent(clearBtn);

        directionalLayout.addComponent(draw);

        super.setUIContent(directionalLayout);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
